package algorithm.sorting.compare.bubblesort;

import algorithm.sorting.ISort;

public class BubbleSorter<T extends Comparable<T>> implements ISort<T> {

	@Override
	public void sort(T[] arr) {
		sort(arr,0,arr.length-1);
	}

	@Override
	public void sort(T[] arr, int head, int end) {
		for(int i=head;i<end;i++){
			for(int j=end;j>i;j--){
				if(arr[j].compareTo(arr[j-1])<0)
					swap(arr,j,j-1);
			}
		}
	}
	private void swap(T[] arr,int i,int j){
		T temp = arr[i];
		arr[i] = arr[j];
		arr[j] = temp;
	}
}
